<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="<%=request.getContextPath()%>/common/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/common/calender.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/common/FSS.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/common/jquery-1.3.min.js"></script>


<script type="text/javascript">

function fnNew(){
	if(checkInput()){
		document.add.submit();
	}
}

function changeValidateCode(obj) {   
 var timenow = new Date().getTime();  

 obj.src="rand.action?d="+timenow;  
} 

function isUseable() {
	var userId = document.getElementById("userId").value;
	var objDisplay = document.getElementById("d_status");
	if(LTrim(userId).length == 0)
	{
		return ;
	}
	
	objDisplay.innerHTML = "<img src='<%=request.getContextPath()%>/images/waiting.gif'/><span style='color:gray;'>&nbsp;待ち......</span>";
	var strUrl = "<s:url action="isUseable" namespace="/user"/>";

	$.post(strUrl, {'user.userId':userId}, function(objRet) {

		if(objRet.status == "true") {
			objDisplay.innerHTML = "<span  style='color:green;'>&nbsp;このユーザＩＤがまだ使われていません！</span>";
			return ;
		}
		if(objRet.status == "false"){
			objDisplay.innerHTML = "<span  style='color:red;'>&nbsp;このユーザＩＤもう存在しています！</span>";
			$("#userId").focus();
		}else {
			alert("エラー！\r\n\r\nエラー：" + objRet.message);
		}
	}, "json");
}

function checkInput(){

	var userId = document.getElementById("userId").value;	    
	var displayName = document.getElementById("displayName").value;	    
	var pwd = document.getElementById("pwd").value;	  		
	var pwdAgain = document.getElementById("pwdAgain").value;       	 		
	var email = document.getElementById("email").value;  
	var question = document.getElementById("question").value;  
	var answer = document.getElementById("answer").value;
	var num_confirm = document.getElementById("num_confirm").value;
	
	if(LTrim(userId).length == 0)
	{
		alert("ユーザーIDを入力してください!");
		$("#userId").focus();
		return false;
	}
	if(LTrim(displayName).length == 0)
	{
		alert("ニックネームを入力してください!");
		$("#displayName").focus();
		return false;
	}
	if(LTrim(pwd).length==0)
	{
		alert("パスワードを入力してください!");
		$("#pwd").focus();
		return false;
	}	
	if(LTrim(pwdAgain).length == 0)
	{
		alert("パスワード再入力を入力してください!");
		$("#pwdAgain").focus();
		return false;
	}
	if(LTrim(email).length == 0)
	{
		alert("Eメールを入力してください!");
		$("#email").focus();
		return false;
	}
	if(LTrim(question).length == 0)
	{
		alert("セキュリティ保護用の質問を入力してください!");
		$("#question").focus();
		return false;
	}
	if(LTrim(answer).length == 0)
	{
		alert("セキュリティー質問の回答を入力してください!");
		$("#answer").focus();
		return false;
	}
	if(LTrim(num_confirm).length == 0)
	{
		alert("確認の数字を入力してください!");
		$("#num_confirm").focus();
		return false;
	}
	
	
		var isNumber =/^[0-9]\d*$/;
		var isAlphabet=/^[a-zA-Z]\D*$/;
		
		if(isNumber.test(userId)){
			alert("ユーザーIDの構成は、アルファベットが必須です！");
			$("#userId").focus();
			return false;
		}
	
		if(pwd.length < 7){
			alert("パスワードの長さは７より大きくしてください！");
			$("#pwd").focus();
			return false;
		}
		
		if(isNumber.test(pwd)||isAlphabet.test(pwd)){
			alert("パスワードの構成は数字とアルファベットが必須です！");
			$("#pwd").focus();
			return false;
		}
		
		if(pwdAgain.length!=pwd.length||pwd!=pwdAgain){
			alert("パスワードの二回の入力が違います！");
			$("#pwdAgain").focus();
			return false;
		}

	<%-- 邮件验证--%>			
	function char_test(chr)
	//字符检测函数
	{
		var i;
		var smallch="abcdefghijklmnopqrstuvwxyz";
		var bigch="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		for(i=0;i<26;i++)
		if(chr==smallch.charAt(i) || chr==bigch.charAt(i))
		return(1);
		return(0);
	}

	function spchar_test(chr)
	//数字和特殊字符检测函数
	{
		var i;
		var spch="_-.0123456789";
		for (i=0;i<13;i++)
		if(chr==spch.charAt(i))
		return(1);
		return(0);
	}

	function email_test(str)
	{
		var i,flag=0;
		var at_symbol=0;
		//“@”检测的位置
		var dot_symbol=0;
		//“.”检测的位置
		if(char_test(str.charAt(0))==0 )
		return(1);
		//首字符必须用字母

		for (i=1;i<str.length;i++)
		if(str.charAt(i)=='@')
		{
			at_symbol=i;
			break;
		}

		if(at_symbol==str.length-1 || at_symbol==0)
		return(2);
//没有邮件服务器域名

		if(at_symbol<3)
		return(3);
//帐号少于三个字符

		if(at_symbol>19 )
		return(4);
//帐号多于十九个字符

		for(i=1;i<at_symbol;i++)
			if(char_test(str.charAt(i))==0 && spchar_test(str.charAt(i))==0)
			return (5);
		for(i=at_symbol+1;i<str.length;i++)
			if(char_test(str.charAt(i))==0 && spchar_test(str.charAt(i))==0)
			return (5);


		for(i=at_symbol+1;i<str.length;i++)
			if(str.charAt(i)=='.') dot_symbol=i;
		for(i=at_symbol+1;i<str.length;i++)
			if(dot_symbol==0 || dot_symbol==str.length-1)
			return (6);

		return (0);
	}  
	
	var str = document.getElementById("email").value;    
	if(email_test(str)!=0)
	{
		alert("Ｅメールの構成は正しくない!");
		$("#email").focus();
		return false;
	}
	
	return true;
}

</script>

</head>
<body id="page5">
<div class="tail-right"></div>
<div class="tail-right-top"></div>
<div class="tail-top">
  <div class="tail-bottom">
    <div class="tail-bg">
      <div class="top-bg">
        <div class="tail-right-bot"></div>
        <div class="bot-bg">
          <div id="main">
            <!-- header -->
            <s:form name="login" action="/fssProject/Login" theme="simple">
            <div id="header">
              <h1><a href="<%=request.getContextPath()%>">fss</a></h1>
              <ul class="top-login">
              <s:if test="#session.user_login==null">
                <li><img alt="" src="../images/userid.gif" /></li>
                <li><input type="text" name="user.userId" id="user_name" /></li>
                <li><img alt="" src="../images/password.gif" /></li>
                <li><input type="password" name="user.pwd" id="password" /></li>
                <li><a class="loginbutton" href="javascript:fnLogin();"></a></li>
                <li><a class="registerbutton" href="/fssProject/user/initRegister" ></a></li>
              </s:if><s:else>
              	<li><h4><s:property value="#session.user_login.displayName"/>,Welcome!</h4></li>
              	<li><a class="mypagebutton" href="/fssProject/user/myInfo"></a></li>
                <li><a class="logoutbutton" href="/fssProject/Logout"></a></li>
                </s:else>
              </ul>
            </div>
            </s:form>
            <div class="extra-img"><img alt="" src="../images/extra-img.png" class="png"/></div>
            <div class="wrapper">
              <!-- nav -->
              <div id="nav">
                <ul>
                 <li><a href="/fssProject/mainPage">ホーム</a></li>
                  <li><a href="/fssProject/experience/list"><s:property value="#session.btn1.content"/></a></li>
                  <li><a href="/fssProject/secondHand/list"><s:property value="#session.btn2.content"/></a></li>
                  <s:if test="#session.user_login.userId in {'fss_admin1','fss_admin2','fss_admin3'}">
                  <li><a href="/fssProject/user/userManage">ユーザ管理</a></li>
                  <li><a href="/fssProject/cmsContent/editCMSContent">CMS変更</a></li>
                  </s:if>
                </ul>
              </div>
              <!-- content -->
              <div id="content">
                <div class="section">
                  <!-- box begin -->
                  <div class="box">
                    <div class="left-top-corner png">
                      <div class="right-top-corner png">
                        <div class="border-top png"></div>
                      </div>
                    </div>
                    <div class="border-left png">
                      <div class="border-right png">
                        <div class="inside png">
                          <h2>登録</h2>
								<div id="message"><h4><font color="Red"><s:property value="msg"/></font></h4></div>
                          <p></p>
                          <form action="add" name="add" method="post" id="contacts-form" >
                            <fieldset>
                              <div class="field">
                                <label>希望するユーザーID:</label>
                                <s:textfield id="userId" name="user.userId" onchange="javascript:isUseable();"/><font color="Red">*</font><div id="d_status"></div>
                              </div>
                              <div class="field">
                                <label>ニックネーム:</label>
                                <s:textfield id="displayName" name="user.displayName"/><font color="Red">*</font>
                              </div>
                              <div class="field">
                                <label>パスワードを作成:</label>
                                <s:password id="pwd" name="user.pwd"/><font color="Red">*</font>
                              </div>
                              <div class="field">
                                <label>パスワード再入力:</label>
                                <s:password id="pwdAgain" name="pwdAgain"/><font color="Red">*</font>
                              </div>
                              <div class="field">
                                <label>Eメール:</label>
                                <s:textfield id="email" name="user.email"/><font color="Red">*</font>
                              </div>
                              <div class="field">
                                <label>氏名:</label>
                                <s:textfield id="realName" name="user.realName"/>
                              </div>
                              <div class="field">
                                <label>国籍:</label>
                                <s:textfield id="nationality" name="user.nationality"/>
                              </div>
                              
                              	<div class="field">
                                	<label>性別:</label>
                                	<s:select id="sex" name="user.sex"
						                 list="%{#{'1':'男','2':'女'}}"/>
                                </div>
                              
                              <div class="field">
                                <label>生年月日:</label>
                                <s:textfield id="birthday" name="user.birthday" onfocus="HS_setDate(this)"/>
                              </div>
                              <div class="field">
                                <label>所属:</label>
                                <s:textfield id="workingPlace" name="user.workingPlace"/>
                              </div>
                              
                              <div class="field">
                                <label>セキュリティ保護用の質問:</label>
                                <s:textfield id="question" name="user.secretQuestion"/><font color="Red">*</font>
                              </div>
                            
                              <div class="field">
                                <label>回答:</label>
                                <s:textfield id="answer" name="user.secretAnswer"/><font color="Red">*</font>
                              </div>
                            
                              <div class="field">
                                <label>数字の確認:</label>
                                <input id="num_confirm" type="text" name="num_confirm"/><font color="Red">*</font>
                              </div>
                              <img src="rand.action" onclick="changeValidateCode(this)"/>
                              
                              <div class="wrapper">
                                <div>
                                <a class="usernewbutton" href="javascript:fnNew();"></a>
                                </div>
                              </div>
                            </fieldset>
                          </form>
                        </div>
                      </div>
                    </div>
                    <div class="left-bot-corner png">
                      <div class="right-bot-corner png">
                        <div class="border-bot png"></div>
                      </div>
                    </div>
                  </div>
                  <!-- box end -->
                </div>
              </div>
            </div>
          </div>
          <!-- footer -->
          <div id="footer">
            <div class="indent">
              <div class="fleft">Copyrights - Ritsumeikan University</div>
              <div class="fright">Designed by: <a href="http://www.ritsumei.jp/ise/index_j.html"><img src="../images/designer.gif" /> </a>Provider</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</body>
</html>